package com.fly.docker.web;

import java.io.File;
import java.io.IOException;
import java.net.URI;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.amihaiemil.docker.Docker;
import com.amihaiemil.docker.TcpDocker;
import com.amihaiemil.docker.UnixDocker;
import com.fly.core.entity.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 
 * https://github.com/amihaiemil/docker-java-api/wiki/Images-API <BR>
 * https://github.com/amihaiemil/docker-java-api/wiki/Containers-API
 * 
 * @author Administrator
 * @version [版本号, 2025年6月17日]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@RestController
@RequestMapping("/docker/rest")
@Api(tags = "docker rest api接口")
public class DockerRestApi
{
    Docker docker;
    
    @ApiOperation("001-Docker 套接字初始化")
    @ApiOperationSupport(order = 10)
    @PostMapping("/init")
    public JsonResult<?> init()
        throws IOException
    {
        docker = new UnixDocker(new File("/var/run/docker.sock"));
        return JsonResult.success(docker.version());
    }
    
    @ApiOperation("001-Docker HTTPS初始化")
    @ApiOperationSupport(order = 10)
    @PostMapping("/remote")
    public JsonResult<?> remote()
        throws IOException
    {
        docker = new TcpDocker(URI.create("https://118.178.86.130:2375"));
        return JsonResult.success(docker.version());
    }
    
}
